"""
Copyright 2012 Wieser Dietmar, Margit Mutschlechner.

This file is part of Multimedia Social Networking Platform.

Multimedia Social Networking Platform is free software: 
you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Multimedia Social Networking Platform is distributed
in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Multimedia Social Networking Platform.  
If not, see <http://www.gnu.org/licenses/>.

"""

from msnp import gui
from msnp.model import DatabaseModel
from msnp.logger import Logger

class DBErrorType():
    """Class containing the different types of database errors. This is one of "select", "insert", "update", "delete", "init", "check", "drop", "trigger", "unknown"."""
    SELECT = "select"
    INSERT = "insert"
    UPDATE = "update"
    DELETE = "delete"
    INIT = "init"
    CHECK = "check"
    DROP = "drop"
    TRIGGER = "trigger"
    UNKNOWN = "unknown"

def processMediaDBError(errorType, traceback):
    """This function emits a signal that notificates the user about an error in the media database.
    
    Args:
        errorType: An instance of the DBErrorType class, either "select", "insert", "update", "delete", "init", "check", "drop", "trigger" or "unkown".
        traceback: A String containing the traceback information.
    """
    Logger.info("media db error occurred: "+errorType)
    gui.MySignal.emitDBExceptionOccurredSignal(errorType, DatabaseModel.DatabaseType.MEDIA, traceback)

def processPlayerDBError(errorType, traceback):
    """This function emits a signal that notificates the user about an error in the player database.
    
    Args:
        errorType: An instance of the DBErrorType class, either "select", "insert", "update", "delete", "init", "check", "drop", "trigger" or "unkown".
        traceback: A String containing the traceback information.
    """
    Logger.info("player db error occurred: "+errorType)
    gui.MySignal.emitDBExceptionOccurredSignal(errorType, DatabaseModel.DatabaseType.PLAYER, traceback)

def processPTPDBError(errorType, traceback):
    """This function emits a signal that notificates the user about an error in the ptp database.
    
    Args:
        errorType: An instance of the DBErrorType class, either "select", "insert", "update", "delete", "init", "check", "drop", "trigger" or "unkown".
        traceback: A String containing the traceback information.
    """
    Logger.info("ptp db error occurred: "+errorType)
    gui.MySignal.emitDBExceptionOccurredSignal(errorType, DatabaseModel.DatabaseType.PTP, traceback)
